<html>
 <head>
  <link href="./leetcode-problem.css" rel="stylesheet" type="text/css">
 </head>
 <body>
  <div class="question_difficulty">
   难度：Hard
  </div>
  <div>
   <h1 class="question_title">
    1037. Minimum Number of K Consecutive Bit Flips
   </h1>
   <p>
    In an array
    <code>
     A
    </code>
    containing only 0s and 1s, a
    <i>
     <code>
      K
     </code>
     -bit flip&nbsp;
    </i>
    consists of choosing a (contiguous) subarray of length
    <code>
     K
    </code>
    and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
   </p>
   <p>
    Return the minimum number of
    <code>
     K
    </code>
    -bit flips required so that there is no 0 in the array.&nbsp; If it is not possible, return
    <code>
     -1
    </code>
    .
   </p>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     Example 1:
    </strong>
   </p>
   <pre>
<strong>Input: </strong>A = <span id="example-input-1-1">[0,1,0]</span>, K = <span id="example-input-1-2">1</span>
<strong>Output: </strong><span id="example-output-1">2</span>
<strong>Explanation: </strong>Flip A[0], then flip A[2].
</pre>
   <div>
    <p>
     <strong>
      Example 2:
     </strong>
    </p>
    <pre>
<strong>Input: </strong>A = <span id="example-input-2-1">[1,1,0]</span>, K = <span id="example-input-2-2">2</span>
<strong>Output: </strong><span id="example-output-2">-1</span>
<strong>Explanation:</strong>&nbsp;No matter how we flip subarrays of size 2, we can't make the array become [1,1,1].
</pre>
    <div>
     <p>
      <strong>
       Example 3:
      </strong>
     </p>
     <pre>
<strong>Input: </strong>A = <span id="example-input-3-1">[0,0,0,1,0,1,1,0]</span>, K = <span id="example-input-3-2">3</span>
<strong>Output: </strong><span id="example-output-3">3</span>
<strong>Explanation:</strong>
Flip A[0],A[1],A[2]:&nbsp;A becomes [1,1,1,1,0,1,1,0]
Flip A[4],A[5],A[6]:&nbsp;A becomes [1,1,1,1,1,0,0,0]
Flip A[5],A[6],A[7]:&nbsp;A becomes [1,1,1,1,1,1,1,1]
</pre>
     <p>
      &nbsp;
     </p>
    </div>
   </div>
   <p>
    <strong>
     Note:
    </strong>
   </p>
   <ol>
    <li>
     <code>
      1 &lt;= A.length &lt;=&nbsp;30000
     </code>
    </li>
    <li>
     <code>
      1 &lt;= K &lt;= A.length
     </code>
    </li>
   </ol>
  </div>
  <div>
   <h1 class="question_title">
    1037. K 连续位的最小翻转次数
   </h1>
   <p>
    在仅包含
    <code>
     0
    </code>
    和
    <code>
     1
    </code>
    的数组
    <code>
     A
    </code>
    中，一次
    <em>
     <code>
      K
     </code>
     位翻转
    </em>
    包括选择一个长度为
    <code>
     K
    </code>
    的（连续）子数组，同时将子数组中的每个
    <code>
     0
    </code>
    更改为
    <code>
     1
    </code>
    ，而每个
    <code>
     1
    </code>
    更改为
    <code>
     0
    </code>
    。
   </p>
   <p>
    返回所需的
    <code>
     K
    </code>
    位翻转的次数，以便数组没有值为
    <code>
     0
    </code>
    的元素。如果不可能，返回
    <code>
     -1
    </code>
    。
   </p>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     示例 1：
    </strong>
   </p>
   <pre><strong>输入：</strong>A = [0,1,0], K = 1
<strong>输出：</strong>2
<strong>解释：</strong>先翻转 A[0]，然后翻转 A[2]。
</pre>
   <p>
    <strong>
     示例 2：
    </strong>
   </p>
   <pre><strong>输入：</strong>A = [1,1,0], K = 2
<strong>输出：</strong>-1
<strong>解释：</strong>无论我们怎样翻转大小为 2 的子数组，我们都不能使数组变为 [1,1,1]。
</pre>
   <p>
    <strong>
     示例 3：
    </strong>
   </p>
   <pre><strong>输入：</strong>A = [0,0,0,1,0,1,1,0], K = 3
<strong>输出：</strong>3
<strong>解释：</strong>
翻转 A[0],A[1],A[2]:&nbsp;A变成 [1,1,1,1,0,1,1,0]
翻转 A[4],A[5],A[6]:&nbsp;A变成 [1,1,1,1,1,0,0,0]
翻转 A[5],A[6],A[7]:&nbsp;A变成 [1,1,1,1,1,1,1,1]
</pre>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     提示：
    </strong>
   </p>
   <ol>
    <li>
     <code>
      1 &lt;= A.length &lt;=&nbsp;30000
     </code>
    </li>
    <li>
     <code>
      1 &lt;= K &lt;= A.length
     </code>
    </li>
   </ol>
  </div>
 </body>
</html>